package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuManageController {

    private ManagerService managerService;

    @Autowired
    public SpuManageController(ManagerService managerService) {
        this.managerService = managerService;
    }

    @GetMapping("/{page}/{size}")
    public Result getSpuInfoPage(@PathVariable Long page, @PathVariable Long size,SpuInfo spuInfo) {
        Page<SpuInfo> spuInfoPage = new Page<>(page, size);
        IPage<SpuInfo> spuInfoPageList = this.managerService.getSpuInfoPage(spuInfoPage,spuInfo);
        return Result.ok(spuInfoPageList);
    }

    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList =  this.managerService.baseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        this.managerService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


}
